# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2024/10/25 16:31

import pandas as pd
from datetime import datetime
from Common.business_common_tool import BusinessCommonTools
from Common.get_sql_object import GetSqlObject
from Common.tool import Tool
from Common.dingtalk import Ding
from datetime import timedelta
from Common.do_mysql import DoMysql
import os
import re

class driver_bill:

    def bill_excel(self,name_list):
        name=re.split(r'[\s,，]+', name_list)  # 同时处理空格、英文逗号、中文逗号
        print(type(name))
        print(name)
        #print(name)

        # 获取当前日期
        now = datetime.now()

        df = {}
        for i in name:
            sql = """
            select id from d_driver where name='@a' or phone='@a';
            """
            mysql_source = GetSqlObject.get_instance("PRO")
            driver_id=BusinessCommonTools().get_query_driver_id('PRO', i,sql, mysql_source)
            #组装成excel数据,放到字典中去
            #组装成excel数据,放到字典中去

            query_driver_bill = BusinessCommonTools().get_query_driver_bill('PRO',driver_id[0]['id'], mysql_source)
            df[i] = pd.DataFrame(query_driver_bill)

        os.makedirs(f'New/司机账单', exist_ok=True)

        # 指定要导出的Excel文件名
        excel_file = f'New/司机账单/账单{now.date()}.xlsx' # 生产环境文件存放地址
        #excel_file = f'File/账单.xlsx'
        excel_file_path = f'http://47.116.122.206/{excel_file}'

        # 使用ExcelWriter对象
        with pd.ExcelWriter(excel_file, engine='xlsxwriter') as writer:
            for i in name:
                df[i].to_excel(writer, sheet_name=i, index=False)
        return_path = excel_file_path.replace("New","New_driver")
        print(return_path)
        return return_path

        # http://47.116.122.206/New/2025-07/%E8%AE%A2%E5%8D%952025-07-01.xlsx

if __name__ == '__main__':
    driver_bill().bill_excel('陈亮,17625890895')


